{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-05-09T02:17:47.716666Z",
     "start_time": "2024-05-09T02:17:47.682685Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3] [1 2 3]\n"
     ]
    },
    {
     "data": {
      "text/plain": "3.3333333333333335"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#两个向量相关性的度量——协方差，相关性越大，说明两个向量变化的方向越相似，协方差越大；反之，说明两个向量变化的方向越不相似，协方差越小。\n",
    "import numpy as np\n",
    "\n",
    "a1=np.array([1,2,3])\n",
    "a2=np.array([1,2,3])\n",
    "print(a1,a2)\n",
    "#计算协方差矩阵\n",
    "(14-4)/3\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3] [3 2 1]\n"
     ]
    },
    {
     "data": {
      "text/plain": "2.0"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "a1=np.array([1,2,3])\n",
    "a2=np.array([3,2,1])\n",
    "print(a1,a2)\n",
    "#计算协方差矩阵\n",
    "(10-4)/3"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-05-09T02:18:53.003980Z",
     "start_time": "2024-05-09T02:18:52.984988500Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
